package com.czd.support.service;

import com.czd.base.service.BaseService;
import com.czd.support.common.Constants;
import com.czd.support.model.RoomUser;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class RoomUserService extends BaseService<RoomUser> {

	/**
	 * 批量插入房间相关用户
	 * @param roomUsers
	 * @return
	 */
	public int insertRoomUserBatch(List<RoomUser> roomUsers) {
		return this.insertAndReturnId("insertRoomUserBatch", roomUsers);
	}
	
	/**
	 * 删除房间相关用户
	 * @param roomId
	 * @return
	 */
	public boolean deleteRoomUserBatch(int roomId) {
		Map<String, Integer> params = new HashMap<String, Integer>();
		params.put("roomId", roomId);
		return this.delete("deleteRoomUser", params);
	}
	
	public List<RoomUser> findRoomUser(int roomId){
		return this.selectList(sqlId("findRoomUser"), roomId);
	}

    public boolean setHomeOwner(int roomId, int homeowner, int userCode) {
        RoomUser roomUser = new RoomUser();
        roomUser.setRoomId(roomId);
        roomUser.setUserId(homeowner);
        roomUser.setCreater(userCode);
        roomUser.setType(Constants.ROOM_HOMEOWNER_CODE);
        return this.insert(sqlId("setHomeOwner"),roomUser);
    }
}
